package com.ztc.ZtcWithdrawalsApply.dao;

import com.aqgj.util.BaseDaoImpl;
import com.aqgj.util.Pager;
import com.ztc.ZtcWithdrawalsApply.bean.ZtcWithdrawalsApply;
import org.springframework.stereotype.Repository;


@Repository("ZtcWithdrawalsApplyDao")
public class ZtcWithdrawalsApplyDao extends BaseDaoImpl<ZtcWithdrawalsApply> {

    public String saveWithdrawalsApply(ZtcWithdrawalsApply ztcWithdrawalsApply){
        this.save(ztcWithdrawalsApply);
        return ztcWithdrawalsApply.getId();
    }

    /** 所有待处理提现列表 */
    public Pager<ZtcWithdrawalsApply> getAllWillOfZtcWithdrawalsApply(Integer pageSize,Integer pageNumber){Pager<ZtcWithdrawalsApply> pager=new Pager<>();
       pager.setPageSize(pageSize);
       pager.setCurrentPage(pageNumber);
       String sql="select * from ztc_withdrawals_apply z where z.status=1 order by z.add_time asc";
       pager.setContent(this.currentSession().createNativeQuery(sql,ZtcWithdrawalsApply.class).setFirstResult(pager.getStart()).setMaxResults(pageSize).getResultList());
       pager.setRecordTotal(this.currentSession().createNativeQuery(sql,ZtcWithdrawalsApply.class).getResultList().size());
       return pager;
    }

    /** 当前公司所有提现列表 */
    public Pager<ZtcWithdrawalsApply> getAllWillOfZtcWithdrawalsApply(String transportId,Integer pageSize,Integer pageNumber,Integer type){
        Pager<ZtcWithdrawalsApply> pager=new Pager<>();
        pager.setPageSize(pageSize);
        pager.setCurrentPage(pageNumber);
        String sql="select * from ztc_withdrawals_apply z where z.business_id='"+transportId+"' and z.business_type=2 order by z.add_time desc";
        if(type==0){
           sql="select * from ztc_withdrawals_apply order by add_time desc";
        }
        pager.setContent(this.currentSession().createNativeQuery(sql,ZtcWithdrawalsApply.class).setFirstResult(pager.getStart()).setMaxResults(pageSize).getResultList());
        pager.setRecordTotal(this.createSQLQuery(sql).getResultList().size());
        return pager;
    }
}